package com.haidechizi.longpolling.client.entity;

import lombok.Getter;

/**
 * @author wangdejun
 * @create 2021/2/24 14:26
 */
@Getter
public class Response<T> {

    private int code;

    private String message;

    private T data;

    private Response() {

    }

    public Response(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder<T> {

        private int code = 200;
        private String message = "访问成功";

        public Builder code(int code) {
            this.code = code;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public Response success() {
            return new Response(this.code, this.message);
        }

        public Response error() {
            return new Response(-1, "服务异常");
        }

        public Response error(String message) {
            return new Response(-1, message);
        }

        public Response build() {
            return new Response(this.code, this.message);
        }

        public Response data(T data) {
            return new Response(this.code, this.message, data);
        }


    }
}
